package releasemanager.actions;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.team.svn.core.operation.local.InfoOperation;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.internal.util.Util;
import org.eclipse.team.svn.ui.utility.UIMonitorUtility;

public class LinkFileSvn implements IObjectActionDelegate {

	private ISelection selection;

	public LinkFileSvn() {
		
		// TODO Auto-generated constructor stub
	}

	@Override
	public void run(IAction action) {
		IFile file = getFile();
		
		IResource res = getResource();
		InfoOperation op = new InfoOperation(res);
		UIMonitorUtility.doTaskBusyDefault(op);
		
		System.out.println(file.getLocation());
		System.out.println(op.getInfo().url);
	}

	@Override
	public void selectionChanged(IAction action, ISelection selection) {
		// TODO Auto-generated method stub
		this.selection = selection;
	}

	@Override
	public void setActivePart(IAction action, IWorkbenchPart targetPart) {
		// TODO Auto-generated method stub
		
	}
	
	private IFile getFile() {
	    return (IFile)
	        ((IStructuredSelection)selection)
	            .getFirstElement();
	  }
	@SuppressWarnings("restriction")
	private IResource getResource(){
		return (IResource)Util.getAdapter(((IStructuredSelection) selection)
	            .getFirstElement(), IResource.class);
		        
	}
}
